<?php
require_once("Validator.php");
require_once("FormValidator.php");
		
class TestAll{
		// Test för Validator.php
		public function ValidatorTest()
		{
			//Test of isShortDate()
            if(!Validator::isShortDate('87-02-15') || !Validator::isShortDate('1987-02-14')
				|| !Validator::isShortDate('870214') || Validator::isShortDate('198702-14')
				|| Validator::isShortDate('1987-02-45') || Validator::isShortDate('1887-02-14')
				|| Validator::isShortDate('1987-13-14') || Validator::isShortDate('1987-00-14')
            ){
         		echo 'Validator: isShortDate() does not work.';
         		return false;
    		}
			
			// Test of isNumeric()
			if (Validator::isNumeric('hej') || !Validator::isNumeric('231')){
				echo 'Validator: isNumeric() does not work.';
				return false;
			}
			// Test of isInteger()
			if(Validator::isInteger('hej') || !Validator::isInteger(32) || Validator::isInteger('43')) {
				echo 'Validator: isInteger() does not work.';
				return false;
			}
			
			// Test of isFloat()
			if(Validator::isFloat('hej')){
				echo 'Validator: isFloat() does not work.';
				return false;
			}
			
			// Test of isEmail()
			if(Validator::isEmailAddress('asddasfsdfsgdf') || Validator::isEmailAddress('11111111')
				|| !Validator::isEmailAddress('cem@nevereversleep.se') || Validator::isEmailAddress('kjal@asdsa.')
				){
					echo 'Validator: isEmail() does not work.';
					return false;
				}
			
			// Test of isRange()
			if(Validator::isInRange('hej', 'på', 'dig') || Validator::isInRange(20, 30, 10)){
				echo 'Validator: isInRange() does not work.';
				return false;
			}
           
		   // Test of isPassword()
           if(Validator::isPassword('=?%¤#”#¤&%') || Validator::isPassword('aaa') || Validator::isPassword('111') ||    
                     Validator::isPassword('aa23a') || Validator::isPassword('aaaaa51aaaaaaaaaaaaa') || 
                     Validator::isPassword('1111111111111111111111111111111') || Validator::isPassword('Jaaahhaa') ||
                    !Validator::isPassword('HIjh!a2Fa32') || !Validator::isPassword('HIjh%_a2Fa32')
					){
						echo 'Validator: isPassword() does not work.';
						return false;
					}
					
			// Test of isPersonalIdNumber()
			if(!Validator::isPersonalIdNumber('780828-8190') ||
			!Validator::isPersonalIdNumber('7808288190') ||
			!Validator::isPersonalIdNumber('19780828-8190') ||
			!Validator::isPersonalIdNumber('197808288190')
			){
				echo 'Validator: isPersonalNumber() does not work.';
				return false;
			}
			
			// Test of sanitizeText()
			$text = '<html><a href="lakasd"><b>Some Link</b></a></html>';
			
			if(Validator::sanitizeText($text, false) != 'Some Link' ||
				Validator::sanitizeText($text, true) != '<a href="lakasd"><b>Some Link</b></a>'
			){
				echo 'Validator: sanitizeText() does not work.';
				return false;
			}
			return true;
		}

		// Test för FormValidator.php
		public function FormValidatorTest(){
			
		$formData = array('uname' => 'hunybuny', 
                          	'password' => 'a31%shSDf',
                          	'email' => 'huny@buny.se',
                           	'age' => 34,
                    		'bday' => '89-12-13',
                            'ssn' => '780828-8190');
							
		// Skapa en instans av FormValidator - skicka med formData som argument. 				
		$formValidator = new FormValidator($formData);

                
                $formValidator->isString( 'uname', 'Please enter a valid string.');
                $formValidator->isPassword('password', 'Please enter a valid password.');
                $formValidator->isEmailAddress('email', 'Please enter a valid E-Mail address.');
                $formValidator->isInteger('age', 'Please enter a valid integer.');
                $formValidator->isInRange('age', 1, 130, 'Please enter a integer between 1 and 130.');
                $formValidator->isShortDate('bday', 'Please enter a valid date (xx-xx-xx).');
                $formValidator->isPersonalIdNumber('ssn', 'Please enter a valid Personal Number');
                
                if($formValidator->hasError()) {
                	echo 'FormValidator: hasErrors() doesnt work.';
                	return false;
				}
			return true;
		}
	}

	$test = new TestAll();
	
	if ($test->validatorTest()) {
		echo "Validator OK<br/>";
	} else {
		 echo "validator NOT OK<br/>"; 
	}
	
	if ($test->FormValidatorTest()) {
		echo "FormValidator OK<br/>";
	} else {
		 echo "FormValidator NOT OK<br/>"; 
	}
?>